<?php
header('Content-Type:application/json;charset=UTF-8');
$conn = mysqli_connect('localhost', 'root', 'root', 'echarts');
if (!$conn) {
    echo json_encode(['code' => 0, 'msg' => '数据库连接失败']);
}
//$sql = "select user.name,salary.create_time,salary.salary as money from user join salary on user.id = salary.user_id where user.id = 19";
//$query = mysqli_query($conn,$sql);
//$result = mysqli_fetch_all($query,MYSQLI_ASSOC);
//$titleName = [];
//$Name = [];
//$titletime = [];
//$salary = [];
//    foreach ($result as $value){
//        array_push($titleName,$value['create_time']);
//        array_push($salary,$value['money']);
//    }
//echo json_encode(['code'=>1,'msg'=>'工资表','data' => [
//    'time' => $titleName,
//    'money' => $salary,
//]]);
$sql = "select salary,year,month from salarytwo where user_id = 19";
$query = mysqli_query($conn,$sql);
$result = mysqli_fetch_all($query,MYSQLI_ASSOC);
$xData = [];
$yData = [];
foreach($result as $val){
    array_push($xData,$val['year'].'-'.$val['month']);
    array_push($yData,$val['salary']);
}
echo json_encode(['code'=>1,'msg'=>'员工薪资图','data' => [
    'xData' => $xData,
    'yData' => $yData,
]]);